
const { shopData } = require("../shop/gameData");

cc.Class({
    extends: cc.Component,

    properties: {
        shopList:cc.Node,
        prefabItem:cc.Prefab,
    },

    // LIFE-CYCLE CALLBACKS:

    onEnable() {
        this.showList();
        // cc.log(this.shopList);
    },

    start () {

    },
    showStock(){
        // let tmp = cc.find('Canvas/show/market/marketAlert');
        // cc.log(tmp)
        // tmp.active = true;
        this.node.active = !this.node.active;
        //显示当前的id
    },
    
    showList(){
        let data = shopData.shopList;
        if(this.shopList){
            this.shopList.children.forEach(val=>{
                val.destroy();
            })
        }
        data.forEach((val)=>{
           if(val.status == 1){
            let item  = cc.instantiate(this.prefabItem);
            this.shopList.addChild(item);
            item.getChildByName("shopName").getComponent(cc.Label).string = `${val.shopName}`;
            //计算库存
            if(val.stock.length>0){
                val.stock.forEach(itemStock=>{
                    if(itemStock.id == material.id){
                        cc.log(itemStock.count)
                        item.getChildByName("stock").getComponent(cc.Label).string = `库存：${itemStock.count}`
                    }else{
                        item.getChildByName("stock").getComponent(cc.Label).string = `库存：0`
                    }
                })
            }else{
                item.getChildByName("stock").getComponent(cc.Label).string = `库存：0`
            }
            
            item.getChildByName("cangku").getComponent(cc.Label).string = `${val.leftStock}`
            item.getChildByName("ice").getComponent(cc.Label).string = `${val.leftIce}`
            item.id = val.id;
           }
           this.shopList.height+=42;
        })
    }
    // update (dt) {},
});
